package two.double_pointer;

/**
 * 盛最多水的容器
 * 时间复杂度：O(n)
 * 思路：双指针夹逼（和中间的柱子无关，只和两个端点有关）
 */
public class MaxArea {
    public int maxArea(int[] height) {
        int i = 0, j = height.length - 1, answer = 0;
        while(i < j){
            answer = Math.max(answer, Math.min(height[i], height[j]) * (j - i));
            if(height[i] == height[j]){
                i++;
                j--;
            }else if(height[i] < height[j]){
                i++;
            }else{
                j--;
            }
        }
        return answer;
    }
}
